import numpy as np

print("创建数组x".center(50, '='))
x = np.random.randint(0, 10, size=(1, 10))
print(x)
print("np.piecewise(x, [x < 3, (3 < x) & (x < 5), x > 7], [-1, 1, lambda x: x * 4])".center(100, '='))
# 非原地操作，小于3的元素变为-1，大于3且小于5的元素变为1，大于7的元素乘以4，其余元素变为0
print(np.piecewise(x, [x < 3, (3 < x) & (x < 5), x > 7], [-1, 1, lambda x: x * 4]))
